use crate::common::Digital;
use std::ops::Deref;
use crate::Digital1Line;

#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
/// represents the high and low levels, or sampling points.
pub enum State {
    ONE,
    ZERO,
}
#[allow(unused)]
///The DigitalState structure represents the output of the digital circuit
///The output may have multiple lines, and each line may have a continuous signal (State).
#[derive(Clone, Debug)]
pub struct DigitalState {
    outputs: Vec<Vec<Option<State>>>,
    lines: usize,
    pre_line_signals: usize,
}

impl DigitalState {
    pub fn new(outputs: Vec<Vec<Option<State>>>, lines: usize, pre_line_signals: usize) -> Self {
        Self {
            outputs,
            lines,
            pre_line_signals,
        }
    }

    pub fn outputs(&self) -> Vec<Vec<Option<State>>> {
        self.outputs.clone()
    }

    pub fn lines(&self) -> usize {
        self.lines
    }

    pub fn per_line_signals_count(&self) -> usize {
        self.pre_line_signals
    }

    pub fn output_line_x(&self, x: usize) -> Vec<Option<State>> {
        match self.outputs().get(x) {
            None => {
                panic!()
            }
            Some(s) => s.clone(),
        }
    }
}

impl Digital1Line for DigitalState{}
impl Digital for DigitalState {
    fn get_output(&self) -> DigitalState {
        self.clone()
    }
}


impl Deref for DigitalState {
    type Target = Vec<Vec<Option<State>>>;

    fn deref(&self) -> &Self::Target {
        &self.outputs
    }
}
